import 'package:flutter/material.dart';
import 'package:oli/shared/size_fit.dart';
import 'package:oli/shared/theme.dart';

void loop() {}

void messageDialog(BuildContext context, {
  @required String title,
  @required String content,
  String confirmText = "確定",
  Function confirmFun = loop
}) {
  showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context){
        return DialogWidget(
          title: title,
          content: Center(
            child:  Text(content, style: TextStyle(fontSize: setRpx(28))),
          ),
          confirmText: confirmText,
          confirmFun: confirmFun,
        );
      }
  );
}

class DialogWidget extends Dialog {
  final String title; //标题
  final Widget content; //内容
  final String confirmText; //"确定"按钮文字
  final Function confirmFun; //确定回调


  DialogWidget({
    Key key,
    @required this.title,
    @required this.content,
    this.confirmText,
    this.confirmFun
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(15),
      child: Material(
        type: MaterialType.transparency,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              decoration: ShapeDecoration(
                color: Color(0xffffffff),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.all(
                    Radius.circular(10),
                  ),
                ),
              ),
              margin: EdgeInsets.all(15),
              child: Column(
                children: <Widget>[
                  SizedBox(height: setRpx(60),),
                  Center(
                    child:  Text(title, style: TextStyle(fontSize: setRpx(32), fontWeight: FontWeight.w700)),
                  ),
                  SizedBox(height: setRpx(30),),
                  content,
                  SizedBox(height: setRpx(60),),
                  Divider(
                    height: setRpx(1),
                    color: Color(0xfff4f4f4),
                  ),
                  Container(
                    decoration: BoxDecoration(
                        boxShadow: []
                    ),
                    width: double.infinity,
                    height: setRpx(100),
                    child: RaisedButton(
                      elevation: 0,
                      highlightElevation: 0,
                      color: Color(0xffffffff),
                      highlightColor: Colors.transparent,
                      splashColor: Colors.transparent,
                      child: Text(confirmText, style: TextStyle(fontSize: setRpx(30))),
                      onPressed: () {
                        confirmFun();
                        Navigator.of(context).pop();
                      },
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _buildBottomCancelButton() {
    return Flexible(
      fit: FlexFit.tight,
      child: FlatButton(
        onPressed: confirmFun,
        child:  Text(title, style: TextStyle(color: Color(0xff666666))),
      ),
    );
  }

}